/**************************************************************************************
 *  Copyright (c)  2010  Pablo Echeverri.
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.3
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License". 
 **************************************************************************************/
package data;

import data.tileables.Fort;

/**************************************************************************************
 * Author(s): Pablo Echeverri
 * holds a list of bonuses that a unit gets when stading on a tile within the IR of fort
 **************************************************************************************/
public class AreaBonus
{
	private LinkedList<Bonus> bonusList=new LinkedList<Bonus>();
	
	public AreaBonus()
	{
		
	}
	/**************************************************************************************
	 * Author(s): Pablo Echeverri
	 * add fort to list
	 **************************************************************************************/
	public void AddFort(Fort fort, int radius )
	{
		this.removeFort(fort);
		this.bonusList.addBack(new Bonus(fort,radius));
	}
	/**************************************************************************************
	 * Author(s): Pablo Echeverri
	 * remove fort from list
	 **************************************************************************************/
	public void removeFort(Fort fort)
	{
		this.bonusList.setToFirst();
		for(int i=0; i<this.bonusList.getSize();i++)
		{
			if(this.bonusList.peekCurrent().fortEquals(fort))
			{
				this.bonusList.removeCurrent();
				return;
			}
			this.bonusList.next();
		}
	}
	/**************************************************************************************
	 * Author(s): Pablo Echeverri
	 * calculates the combined bonuses from all forts in the list
	 **************************************************************************************/
	public int calculateBonus()
	{
		int bonus=0;
		this.bonusList.setToFirst();
		for(int i=0; i<this.bonusList.getSize();i++)
		{
			bonus+=this.bonusList.peekCurrent().getBonus();
			this.bonusList.next();
		}
		return bonus;
	}
	/**************************************************************************************
	 * Author(s): Pablo Echeverri
	 * checks if a given fort is in bonus list
	 **************************************************************************************/
	public boolean hasFort(Fort fort)
	{
		this.bonusList.setToFirst();
		for(int i=0; i<this.bonusList.getSize();i++)
		{
			if(this.bonusList.peekCurrent().fortEquals(fort))
			{
				return true;
			}
			this.bonusList.next();
		}
		return false;
	}
}